package tg.app.opticket;

import java.rmi.RemoteException;
import java.util.HashSet;

import psdi.mbo.Mbo;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSet;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboValueInfo;
import psdi.util.MXException;

/***
 * 
 * @author pzx
 *
 */
public class OpTask extends Mbo implements OpTaskRemote {
	
	private static final long serialVersionUID = 1L;
	private static HashSet skipFieldCopy = new HashSet();
	private static boolean isHashSetLoaded = false;

	public OpTask(MboSet mboset) throws RemoteException {
		super(mboset);
	}

	public void add() throws MXException, RemoteException {
		super.add();
		MboRemote owner = getOwner();
		if (owner instanceof OpTicketRemote) {
			owner = (OpTicketRemote) owner;
			setValue("opticketid", owner.getString("opticketid"), 11L);
			setValue("TASKID", this.getThisMboSet().max("TASKID") + 1, 11L);
		}
	}

	public void save() throws MXException, RemoteException {
		super.save();
		MboRemote parent = this.getOwner();
		if (parent != null && parent instanceof OpTicket) {
			parent.setValue("GOITEM", this.getThisMboSet().count(), 11L);
		}
		super.save();
	}
 
    protected boolean skipCopyField(MboValueInfo mbovalueinfo) throws RemoteException, MXException {
        if (!isHashSetLoaded){
            loadSkipFieldCopyHashSet();
        }
        return skipFieldCopy.contains(mbovalueinfo.getName());
    }
    
    public static HashSet getHashSet() throws MXException, RemoteException {
        return skipFieldCopy;
    } 

	private static void loadSkipFieldCopyHashSet() throws MXException, RemoteException {
		isHashSetLoaded = true;
		skipFieldCopy.add("OPTICKETID");
		skipFieldCopy.add("ISCOMPLETE");
		skipFieldCopy.add("STATUS");
		skipFieldCopy.add("STATUSDATE");
		skipFieldCopy.add("REPORTEDBYID");
		
	}
}
